{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5ad3dcb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import os\n",
    "from tqdm import tqdm\n",
    "from glob import glob\n",
    "from multiprocess import Pool\n",
    "import itertools\n",
    "import string\n",
    "\n",
    "printable = set(string.printable)\n",
    "timestamps = [i * 0.02 for i in range(1500 + 1)]\n",
    "\n",
    "def chunks(l, n):\n",
    "    for i in range(0, len(l), n):\n",
    "        yield (l[i: i + n], i // n)\n",
    "\n",
    "def multiprocessing(strings, function, cores=6, returned=True):\n",
    "    df_split = chunks(strings, len(strings) // cores)\n",
    "    pool = Pool(cores)\n",
    "    pooled = pool.map(function, df_split)\n",
    "    pool.close()\n",
    "    pool.join()\n",
    "\n",
    "    if returned:\n",
    "        return list(itertools.chain(*pooled))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "41db4cf5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# folders = [\n",
    "#     'klasik_processed',\n",
    "#     'malaysian-podcast_processed',\n",
    "#     'sg-podcast_processed',\n",
    "#     'filtered-24k_processed',\n",
    "#     'parlimen-24k-chunk_processed',\n",
    "# ]\n",
    "\n",
    "# audio = []\n",
    "# for f in folders:\n",
    "#     audio.extend(glob(os.path.join(f, '**/*.mp3'), recursive = True))\n",
    "    \n",
    "    \n",
    "# def loop(files):\n",
    "#     files, _ = files\n",
    "#     for f in tqdm(files):\n",
    "#         new_f = ''.join([c for c in f if c in printable])\n",
    "#         if new_f != f:\n",
    "#             folder = os.path.split(new_f)[0]\n",
    "#             os.makedirs(folder, exist_ok = True)\n",
    "#             os.replace(f, new_f)\n",
    "            \n",
    "            \n",
    "# multiprocessing(audio, loop, cores = 20, returned = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "408d1e90",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2449331"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "files = glob('*_alignment/**/*.alignment', recursive = True)\n",
    "files = [f for f in files if 'prepared-pseudolabel' not in f]\n",
    "len(files)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "913356d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'klasik_processed_alignment/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_22.alignment'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "files[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "25d7034a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import Counter\n",
    "\n",
    "def detect_repeated_phrases(text, n=3):\n",
    "    words = text.lower().split()\n",
    "    phrases = [' '.join(words[i:i+n]) for i in range(len(words)-n+1)]\n",
    "    counter = Counter(phrases)\n",
    "    return [phrase for phrase, count in counter.items() if count > 2]\n",
    "\n",
    "def loop(files):\n",
    "    files, _ = files\n",
    "    filtered = []\n",
    "    for f in tqdm(files):\n",
    "        with open(f) as fopen:\n",
    "            d = json.load(fopen)\n",
    "        \n",
    "        if d[-1]['start'] <= 4:\n",
    "            continue\n",
    "        \n",
    "        scores = [d_['score'] for d_ in d if d_['score'] <= -12]\n",
    "        if len(scores):\n",
    "            continue\n",
    "        \n",
    "        t_ = ' '.join([d_['text'] for d_ in d])\n",
    "        if len(detect_repeated_phrases(t_, n=3)):\n",
    "            continue\n",
    "        \n",
    "        filtered.append(f)\n",
    "        \n",
    "    return filtered"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0df427ba",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 25579.96it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 25342.39it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26654.30it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 24024.75it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 24463.60it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26308.04it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26661.62it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26627.60it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26471.32it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26240.80it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26512.97it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26418.91it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26787.49it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26492.23it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26619.20it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26759.87it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26529.56it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26192.07it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:03<00:00, 26333.12it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 27631.96it/s]\n",
      "100%|████████████████████████████████████████████████████████████████████████████████████| 11/11 [00:00<00:00, 16103.78it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 29493.22it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 29443.54it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 29710.24it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 29607.38it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 29516.00it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 29300.58it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 29822.94it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 29609.62it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 30072.02it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 81644/81644 [00:02<00:00, 29972.68it/s]\n"
     ]
    }
   ],
   "source": [
    "filtered = multiprocessing(files, loop, cores = 30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "4f5771fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "599922"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(filtered)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2ba5106c",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████| 599922/599922 [00:05<00:00, 100355.08it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "defaultdict(int,\n",
       "            {'klasik_processed_alignment': 4125,\n",
       "             'malaysian-podcast_processed_alignment': 27982,\n",
       "             'sg-podcast_processed_alignment': 6708,\n",
       "             'filtered-24k_processed_alignment': 217029,\n",
       "             'parlimen-24k-chunk_processed_alignment': 268365})"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from collections import defaultdict\n",
    "\n",
    "counts = defaultdict(int)\n",
    "selected = defaultdict(list)\n",
    "for f in tqdm(filtered):\n",
    "    new_f = ''.join([c for c in f if c in printable])\n",
    "    audio_filename = new_f.replace('_alignment/', '/').replace('.alignment', '.mp3')\n",
    "    if not os.path.exists(audio_filename):\n",
    "        continue\n",
    "    \n",
    "    counts[f.split('/')[0]] += 1\n",
    "    selected[f.split('/')[0]].append({\n",
    "        'alignment_filename': f,\n",
    "        'audio_filename': audio_filename,\n",
    "    })\n",
    "counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "fa171afd",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████| 4125/4125 [00:00<00:00, 2230150.04it/s]\n",
      "100%|████████████████████████████████████████████████████████████████████████████| 27982/27982 [00:00<00:00, 2521809.51it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████| 6708/6708 [00:00<00:00, 2510967.54it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████| 200000/200000 [00:00<00:00, 1692893.31it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████| 200000/200000 [00:00<00:00, 1220761.33it/s]\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "data = []\n",
    "for k, v in selected.items():\n",
    "    if len(v) > 200000:\n",
    "        rows = random.sample(v, 200000)\n",
    "    else:\n",
    "        rows = v\n",
    "    for row in tqdm(rows):\n",
    "        data.append({**row})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "968ac90f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "438815"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "e768552f",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'alignment_filename': 'klasik_processed_alignment/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_22.alignment',\n",
       " 'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_22.mp3'}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[0]['audio_filename']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "6d5b9f85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ed67556c3bdd4a358f24e9a519967b16",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "fasttext.ftz:   0%|          | 0.00/331M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from huggingface_hub import hf_hub_download\n",
    "import fasttext\n",
    "\n",
    "filename = hf_hub_download(\n",
    "    repo_id=\"mesolitica/fasttext-language-detection-bahasa-en\", \n",
    "    filename=\"fasttext.ftz\"\n",
    ")\n",
    "lang_model = fasttext.load_model(filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "f311b1a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "from xml.etree.ElementTree import Element, SubElement, tostring\n",
    "import xml.dom.minidom\n",
    "\n",
    "pattern = re.compile(r'<\\|([\\d.]+)\\|>([^<]*)')\n",
    "\n",
    "def format_srt_time(seconds):\n",
    "    hours = int(seconds // 3600)\n",
    "    minutes = int((seconds % 3600) // 60)\n",
    "    secs = int(seconds % 60)\n",
    "    millis = int((seconds - int(seconds)) * 1000)\n",
    "    return f\"{hours:02}:{minutes:02}:{secs:02},{millis:03}\"\n",
    "\n",
    "def get_subtitles(input_text):\n",
    "    entries = pattern.findall(input_text)\n",
    "\n",
    "    subtitles = []\n",
    "    for i in range(len(entries) - 1):\n",
    "        start_time = float(entries[i][0])\n",
    "        end_time = float(entries[i + 1][0])\n",
    "        text = entries[i][1].strip()\n",
    "        if text:\n",
    "            subtitles.append((start_time, end_time, text))\n",
    "            \n",
    "    return subtitles\n",
    "\n",
    "def get_srt(subtitles):\n",
    "    srt_output = \"\"\n",
    "    for idx, (start, end, text) in enumerate(subtitles, start=1):\n",
    "        srt_output += f\"{idx}\\n\"\n",
    "        srt_output += f\"{format_srt_time(start)} --> {format_srt_time(end)}\\n\"\n",
    "        srt_output += f\"{text}\\n\\n\"\n",
    "    return srt_output\n",
    "\n",
    "def format_ttml_time(seconds):\n",
    "    return f\"{int(seconds // 3600):02}:{int((seconds % 3600) // 60):02}:{int(seconds % 60):02}.{int((seconds % 1) * 1000):03}\"\n",
    "\n",
    "def get_tt(subtitles):\n",
    "    tt = Element('tt', xmlns=\"http://www.w3.org/ns/ttml\")\n",
    "    body = SubElement(tt, 'body')\n",
    "    div = SubElement(body, 'div')\n",
    "\n",
    "    for start, end, text in subtitles:\n",
    "        SubElement(div, 'p', begin=format_ttml_time(start), end=format_ttml_time(end)).text = text\n",
    "\n",
    "    xml_str = xml.dom.minidom.parseString(tostring(tt)).toprettyxml(indent=\"  \")\n",
    "    return str(xml_str)\n",
    "\n",
    "word = [\n",
    "    'audio to Whisper ASR format word timestamp',\n",
    "    'transcribe the audio into Whisper format in word timestamp'\n",
    "]\n",
    "\n",
    "srt = [\n",
    "    'audio to SRT format',\n",
    "    'transcribe the audio into srt format',\n",
    "]\n",
    "\n",
    "ttml = [\n",
    "    'audio to TTML format',\n",
    "    'transcribe the audio into ttml format',\n",
    "]\n",
    "\n",
    "segment = [\n",
    "    'audio to Whisper ASR format',\n",
    "    'transcribe the audio into Whisper format'\n",
    "]\n",
    "\n",
    "transcribe = ['transcribe the audio']\n",
    "\n",
    "def loop(rows):\n",
    "    rows, _ = rows\n",
    "    data = []\n",
    "    for row in tqdm(rows):\n",
    "        with open(row['alignment_filename']) as fopen:\n",
    "            c = json.load(fopen)\n",
    "        min_t = min([c_['start'] for c_ in c])\n",
    "        segments, temp = [], [c[0]]\n",
    "        last_t = c[0]['end']\n",
    "        for c_ in c[1:]:\n",
    "            if (c_['start'] - last_t) > 0.3:\n",
    "                segments.append(temp)\n",
    "                temp = []\n",
    "\n",
    "            last_t = c_['end']\n",
    "            temp.append(c_)\n",
    "\n",
    "        if len(temp):\n",
    "            segments.append(temp)\n",
    "        \n",
    "        ts = []\n",
    "        for s in segments:\n",
    "            start = min(timestamps, key=lambda t: abs(t - (s[0]['start'] - min_t)))\n",
    "            end = min(timestamps, key=lambda t: abs(t - (s[-1]['end'] - min_t)))\n",
    "            w = ' '.join([c_['text'] for c_ in s])\n",
    "            t = f\"<|{start:.2f}|> {w}<|{end:.2f}|>\"\n",
    "            ts.append(t)\n",
    "        \n",
    "        ts = ''.join(ts)\n",
    "        \n",
    "        cleaned_text = re.sub(r\"<\\|.*?\\|>\", \"\", ts).strip()\n",
    "        if lang_model.predict(cleaned_text)[0][0] == '__label__english':\n",
    "            predict_lang = 'en'\n",
    "        else:\n",
    "            predict_lang = 'ms'\n",
    "        \n",
    "        new_text = f\"<|startoftranscript|><|{predict_lang}|><|transcribe|>{ts}<|endoftext|>\"\n",
    "            \n",
    "        data.append({\n",
    "            'question': random.choice(segment),\n",
    "            'answer': new_text,\n",
    "            'audio_filename': row['audio_filename'],\n",
    "        })\n",
    "        \n",
    "        try:\n",
    "            input_text = new_text.split('<|transcribe|>')[1]\n",
    "            subtitles = get_subtitles(input_text)\n",
    "            \n",
    "            if random.random() > 0.9:\n",
    "                try:\n",
    "                    data.append({\n",
    "                        'question': random.choice(srt),\n",
    "                        'answer': get_srt(subtitles),\n",
    "                        'audio_filename': row['audio_filename'],\n",
    "                    })\n",
    "                except:\n",
    "                    pass\n",
    "            \n",
    "            if random.random() > 0.9:\n",
    "                try:\n",
    "                    data.append({\n",
    "                        'question': random.choice(ttml),\n",
    "                        'answer': get_tt(subtitles),\n",
    "                        'audio_filename': row['audio_filename'],\n",
    "                    })\n",
    "                except Exception as e:\n",
    "                    print(e)\n",
    "                    pass\n",
    "        except:\n",
    "            pass\n",
    "        \n",
    "        if random.random() > 0.4:\n",
    "            ts = []\n",
    "\n",
    "            for c_ in c:\n",
    "                start = min(timestamps, key=lambda t: abs(t - (c_['start'] - min_t)))\n",
    "                end = min(timestamps, key=lambda t: abs(t - (c_['end'] - min_t)))\n",
    "                w = c_['text']\n",
    "                t = f\"<|{start:.2f}|> {w}<|{end:.2f}|>\"\n",
    "                ts.append(t)\n",
    "\n",
    "            ts = ''.join(ts)\n",
    "            ts = f\"<|startoftranscript|><|{predict_lang}|><|transcribeprecise|>{ts}<|endoftext|>\"\n",
    "            \n",
    "            data.append({\n",
    "                'question': random.choice(word),\n",
    "                'answer': ts,\n",
    "                'audio_filename': row['audio_filename'],\n",
    "            })\n",
    "            \n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "b08d3aac",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 313.87it/s]\n"
     ]
    }
   ],
   "source": [
    "alignment = loop((data[:10], 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "09987d1d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'question': 'transcribe the audio into Whisper format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Sangat menarik sebenarnya rumah ini kerana<|1.58|><|2.40|> di dalam rumah ini sebenarnya ini adalah<|4.44|><|4.78|> replika ataupun bukan rumah sebenar.<|7.02|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_22.mp3'},\n",
       " {'question': 'audio to Whisper ASR format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Walaupun rumah ini dijadikan rumah inap desa<|2.44|><|3.08|> dan dalam usaha mendekatkan peminat dengan Nordin Ahmad,<|6.18|><|6.56|> pengunjung<|7.14|><|7.56|> dapat bermalam atau tinggal di sini<|9.44|><|9.88|> dengan kemudahan yang serba lengkap.<|11.80|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_13.mp3'},\n",
       " {'question': 'audio to SRT format',\n",
       "  'answer': '1\\n00:00:00,000 --> 00:00:02,439\\nWalaupun rumah ini dijadikan rumah inap desa\\n\\n2\\n00:00:03,080 --> 00:00:06,179\\ndan dalam usaha mendekatkan peminat dengan Nordin Ahmad,\\n\\n3\\n00:00:06,559 --> 00:00:07,139\\npengunjung\\n\\n4\\n00:00:07,559 --> 00:00:09,439\\ndapat bermalam atau tinggal di sini\\n\\n5\\n00:00:09,880 --> 00:00:11,800\\ndengan kemudahan yang serba lengkap.\\n\\n',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_13.mp3'},\n",
       " {'question': 'audio to Whisper ASR format word timestamp',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribeprecise|><|0.00|> Walaupun<|0.38|><|0.46|> rumah<|0.68|><|0.80|> ini<|0.94|><|1.06|> dijadikan<|1.54|><|1.60|> rumah<|1.80|><|1.88|> inap<|2.08|><|2.16|> desa<|2.44|><|3.08|> dan<|3.28|><|3.46|> dalam<|3.70|><|3.78|> usaha<|4.06|><|4.10|> mendekatkan<|4.64|><|4.74|> peminat<|5.14|><|5.20|> dengan<|5.42|><|5.48|> Nordin<|5.78|><|5.88|> Ahmad,<|6.18|><|6.56|> pengunjung<|7.14|><|7.56|> dapat<|7.88|><|7.96|> bermalam<|8.42|><|8.54|> atau<|8.68|><|8.74|> tinggal<|9.00|><|9.06|> di<|9.10|><|9.20|> sini<|9.44|><|9.88|> dengan<|10.10|><|10.18|> kemudahan<|10.66|><|10.72|> yang<|10.84|><|10.92|> serba<|11.18|><|11.26|> lengkap.<|11.80|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_13.mp3'},\n",
       " {'question': 'audio to Whisper ASR format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Seniman Nordin Ahmad adalah kelahiran kampung-kota Permatang Pasir, Pulau Pinang.<|4.92|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_7.mp3'},\n",
       " {'question': 'audio to SRT format',\n",
       "  'answer': '1\\n00:00:00,000 --> 00:00:04,919\\nSeniman Nordin Ahmad adalah kelahiran kampung-kota Permatang Pasir, Pulau Pinang.\\n\\n',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_7.mp3'},\n",
       " {'question': 'audio to TTML format',\n",
       "  'answer': '<?xml version=\"1.0\" ?>\\n<tt xmlns=\"http://www.w3.org/ns/ttml\">\\n  <body>\\n    <div>\\n      <p begin=\"00:00:00.000\" end=\"00:00:04.919\">Seniman Nordin Ahmad adalah kelahiran kampung-kota Permatang Pasir, Pulau Pinang.</p>\\n    </div>\\n  </body>\\n</tt>\\n',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_7.mp3'},\n",
       " {'question': 'audio to Whisper ASR format word timestamp',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribeprecise|><|0.00|> Seniman<|0.40|><|0.48|> Nordin<|0.82|><|0.94|> Ahmad<|1.30|><|1.46|> adalah<|1.72|><|1.80|> kelahiran<|2.20|><|2.34|> kampung-kota<|3.02|><|3.16|> Permatang<|3.58|><|3.66|> Pasir,<|4.06|><|4.16|> Pulau<|4.38|><|4.44|> Pinang.<|4.92|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_7.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Uh, Allah, Ya, ham, no, dan Ahmad.<|1.62|><|2.02|> Tetapi, ia dibangunkan,<|3.78|><|4.12|> uh,<|4.48|><|5.26|> khusus untuk mengenang,<|6.44|><|7.12|> uh, Allah, Ya, ham, no, dan Ahmad.<|8.54|><|9.08|> Di sini, kita dapat, uh, melihat bagaimana<|11.84|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_23.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> ia juga salah satu lagi produk pelancongan<|2.44|><|2.86|> yang mampu menggambik orang luar<|4.68|><|5.08|> datang ke desa<|6.04|><|6.54|> yang terkenal dengan sawah padi dan pantai.<|9.12|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_14.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format in word timestamp',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribeprecise|><|0.00|> ia<|0.12|><|0.24|> juga<|0.46|><|0.62|> salah<|0.84|><|0.90|> satu<|1.10|><|1.18|> lagi<|1.38|><|1.46|> produk<|1.78|><|1.82|> pelancongan<|2.44|><|2.86|> yang<|3.02|><|3.10|> mampu<|3.50|><|3.72|> menggambik<|4.16|><|4.22|> orang<|4.36|><|4.42|> luar<|4.68|><|5.08|> datang<|5.48|><|5.58|> ke<|5.62|><|5.74|> desa<|6.04|><|6.54|> yang<|6.68|><|6.72|> terkenal<|7.08|><|7.12|> dengan<|7.30|><|7.38|> sawah<|7.60|><|7.66|> padi<|7.90|><|8.10|> dan<|8.24|><|8.36|> pantai.<|9.12|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_14.mp3'},\n",
       " {'question': 'audio to Whisper ASR format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Menerusi kunjungan orang ramai ke rumah Nordin Ahmad secara tidak langsung,<|3.76|><|4.18|> pengunjung dapat mengenali dengan lebih dekat<|6.70|><|7.06|> siapakah seniman Nordin Ahmad itu.<|9.64|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_15.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Rumah ini sebenarnya adalah replika<|1.50|><|1.84|> khusus untuk<|2.52|><|3.12|> mengabadikan ataupun mengenang kembali,<|5.14|><|5.86|> ah, seniman yang<|7.10|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_2.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Uh,<|0.02|><|0.86|> suasana<|1.30|><|1.68|> reka bentuk rumah ini,<|2.96|><|3.68|> uh,<|3.76|><|4.34|> sangat tradisional.<|5.32|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_24.mp3'},\n",
       " {'question': 'audio to Whisper ASR format word timestamp',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribeprecise|><|0.00|> Uh,<|0.02|><|0.86|> suasana<|1.30|><|1.68|> reka<|1.84|><|1.92|> bentuk<|2.28|><|2.54|> rumah<|2.76|><|2.82|> ini,<|2.96|><|3.68|> uh,<|3.76|><|4.34|> sangat<|4.56|><|4.62|> tradisional.<|5.32|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_24.mp3'},\n",
       " {'question': 'audio to Whisper ASR format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Beliau menghempuskan nafas terakhir di sisi istrinya,<|2.98|><|3.48|> Salma Ibrahim,<|4.42|><|4.82|> di Hospital Besar Singapura.<|6.94|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_20.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Community di Selangor yang berbesar hati mewujudkan satu tempat sebagai bercutanda<|4.86|><|5.36|> yang boleh kita kenang siapa itu Nordin Ahmad.<|7.78|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_10.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format in word timestamp',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribeprecise|><|0.00|> Community<|0.54|><|0.70|> di<|0.74|><|0.84|> Selangor<|1.24|><|1.34|> yang<|1.46|><|1.52|> berbesar<|1.94|><|2.02|> hati<|2.30|><|2.44|> mewujudkan<|3.10|><|3.24|> satu<|3.42|><|3.50|> tempat<|3.80|><|3.86|> sebagai<|4.14|><|4.26|> bercutanda<|4.86|><|5.36|> yang<|5.50|><|5.56|> boleh<|5.74|><|5.78|> kita<|5.92|><|6.00|> kenang<|6.32|><|6.44|> siapa<|6.66|><|6.76|> itu<|6.86|><|6.94|> Nordin<|7.22|><|7.28|> Ahmad.<|7.78|><|endoftext|>',\n",
       "  'audio_filename': 'klasik_processed/RUMAH NORDIN AHMAD [iATLCGdiHVw]/RUMAH NORDIN AHMAD [iATLCGdiHVw]_10.mp3'}]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alignment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "01bb2ff8",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:35<00:00, 244.05it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████████| 15/15 [00:00<00:00, 213.01it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:34<00:00, 251.92it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:36<00:00, 239.77it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:40<00:00, 217.18it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:36<00:00, 238.55it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:36<00:00, 242.36it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:40<00:00, 214.93it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 234.89it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 213.43it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 209.67it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 209.91it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 236.80it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:35<00:00, 244.60it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:40<00:00, 214.68it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 213.71it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:40<00:00, 217.58it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 237.08it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 234.35it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:39<00:00, 219.96it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:40<00:00, 214.23it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 213.80it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:35<00:00, 247.54it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:36<00:00, 238.58it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:42<00:00, 208.71it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:39<00:00, 219.84it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 209.53it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 233.89it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:36<00:00, 238.17it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:43<00:00, 202.62it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 212.38it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:42<00:00, 205.92it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 212.70it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:42<00:00, 208.93it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 236.78it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 210.39it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:43<00:00, 201.40it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 231.68it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 213.22it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:40<00:00, 215.33it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 213.09it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:36<00:00, 237.95it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 209.57it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 234.04it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:36<00:00, 240.41it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:36<00:00, 239.42it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 235.68it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:37<00:00, 232.32it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:36<00:00, 237.51it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:41<00:00, 210.03it/s]\n",
      "100%|██████████████████████████████████████████████████████████████████████████████████| 8776/8776 [00:38<00:00, 229.94it/s]\n"
     ]
    }
   ],
   "source": [
    "alignment = multiprocessing(data, loop, cores = 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "58875b77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "790737"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(alignment)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "e1a85484",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'question': 'audio to Whisper ASR format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Dengan mengambil kira dan memperhalusi perkara-perkara di atas,<|3.16|><|3.60|> pihak Kementerian<|4.44|><|5.00|> akan seterusnya meneliti<|6.68|><|endoftext|>',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 22 November 2023  Sesi Pagi [S1iU7QQQ-BU]_000/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 22 November 2023  Sesi Pagi [S1iU7QQQ-BU]_000_300.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Naik tarap hospital Miri dan hospital Sibu<|3.76|><|5.16|> ke tarap hospital negeri.<|6.80|><|8.36|> Sama tarap<|9.18|><|9.48|> dengan<|9.82|><|10.58|> hospital umum<|11.50|><|12.34|> Sarawak di Kuching.<|13.40|><|endoftext|>',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG  Persidangan Dewan Negara 14 Oktober 2021   Sesi Petang [p2rKt1JwaAA]_001/parlimen-24k-LANGSUNG  Persidangan Dewan Negara 14 Oktober 2021   Sesi Petang [p2rKt1JwaAA]_001_2.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format in word timestamp',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribeprecise|><|0.00|> Naik<|0.28|><|0.46|> tarap<|0.86|><|1.10|> hospital<|1.80|><|1.96|> Miri<|2.26|><|2.50|> dan<|2.66|><|2.90|> hospital<|3.38|><|3.48|> Sibu<|3.76|><|5.16|> ke<|5.22|><|5.40|> tarap<|5.76|><|5.96|> hospital<|6.44|><|6.52|> negeri.<|6.80|><|8.36|> Sama<|8.62|><|8.80|> tarap<|9.18|><|9.48|> dengan<|9.82|><|10.58|> hospital<|11.08|><|11.22|> umum<|11.50|><|12.34|> Sarawak<|12.74|><|12.82|> di<|12.86|><|12.94|> Kuching.<|13.40|><|endoftext|>',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG  Persidangan Dewan Negara 14 Oktober 2021   Sesi Petang [p2rKt1JwaAA]_001/parlimen-24k-LANGSUNG  Persidangan Dewan Negara 14 Oktober 2021   Sesi Petang [p2rKt1JwaAA]_001_2.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Rantaian bekalan bahan mentah getah<|2.20|><|2.68|> melalui peniaga getah<|3.98|><|4.40|> atau korporasi<|5.26|><|5.94|> secara menggalakkan mereka mengeluarkan latex bagi menampung bekalan latex negara<|10.44|><|11.12|> untuk sektor hiliran.<|12.50|><|13.30|> Bagi menggalakkan penyertaan,<|14.86|><|endoftext|>',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 18 September 2023  Sesi Pagi [IA6anyIuFrU]_001/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 18 September 2023  Sesi Pagi [IA6anyIuFrU]_001_291.mp3'},\n",
       " {'question': 'audio to TTML format',\n",
       "  'answer': '<?xml version=\"1.0\" ?>\\n<tt xmlns=\"http://www.w3.org/ns/ttml\">\\n  <body>\\n    <div>\\n      <p begin=\"00:00:00.000\" end=\"00:00:02.200\">Rantaian bekalan bahan mentah getah</p>\\n      <p begin=\"00:00:02.680\" end=\"00:00:03.980\">melalui peniaga getah</p>\\n      <p begin=\"00:00:04.400\" end=\"00:00:05.259\">atau korporasi</p>\\n      <p begin=\"00:00:05.940\" end=\"00:00:10.439\">secara menggalakkan mereka mengeluarkan latex bagi menampung bekalan latex negara</p>\\n      <p begin=\"00:00:11.119\" end=\"00:00:12.500\">untuk sektor hiliran.</p>\\n      <p begin=\"00:00:13.300\" end=\"00:00:14.859\">Bagi menggalakkan penyertaan,</p>\\n    </div>\\n  </body>\\n</tt>\\n',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 18 September 2023  Sesi Pagi [IA6anyIuFrU]_001/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 18 September 2023  Sesi Pagi [IA6anyIuFrU]_001_291.mp3'},\n",
       " {'question': 'audio to Whisper ASR format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Apa yang perlu saya nak menyebutkan,<|1.84|><|2.36|> bahawa bila sebut alam sekitar,<|4.10|><|4.66|> ia melibatkan juga pencemaran air.<|6.98|><|endoftext|>',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 27 Februari 2023  Sesi Petang [k2TjU8JaNeg]_002/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 27 Februari 2023  Sesi Petang [k2TjU8JaNeg]_002_186.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format in word timestamp',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribeprecise|><|0.00|> Apa<|0.16|><|0.24|> yang<|0.36|><|0.42|> perlu<|0.66|><|0.88|> saya<|1.00|><|1.04|> nak<|1.12|><|1.18|> menyebutkan,<|1.84|><|2.36|> bahawa<|2.62|><|2.70|> bila<|2.84|><|2.96|> sebut<|3.22|><|3.36|> alam<|3.56|><|3.66|> sekitar,<|4.10|><|4.66|> ia<|4.70|><|4.80|> melibatkan<|5.38|><|5.48|> juga<|5.70|><|5.84|> pencemaran<|6.40|><|6.56|> air.<|6.98|><|endoftext|>',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 27 Februari 2023  Sesi Petang [k2TjU8JaNeg]_002/parlimen-24k-LANGSUNG  Persidangan Dewan Rakyat 27 Februari 2023  Sesi Petang [k2TjU8JaNeg]_002_186.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribe|><|0.00|> Masjid dibakar, kampung dibakar, anak-anak dibunuh, orang tua dibunuh.<|4.42|><|4.98|> Mereka pilih tempat kita.<|5.90|><|6.76|> Jadi, mereka ini,<|7.76|><|endoftext|>',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG Persidangan Dewan Rakyat  Mesyuarat Kedua Penggal Ketiga  1 Julai 2024  Sesi Petang [JZLbr5Nbxrs]_001/parlimen-24k-LANGSUNG Persidangan Dewan Rakyat  Mesyuarat Kedua Penggal Ketiga  1 Julai 2024  Sesi Petang [JZLbr5Nbxrs]_001_115.mp3'},\n",
       " {'question': 'transcribe the audio into ttml format',\n",
       "  'answer': '<?xml version=\"1.0\" ?>\\n<tt xmlns=\"http://www.w3.org/ns/ttml\">\\n  <body>\\n    <div>\\n      <p begin=\"00:00:00.000\" end=\"00:00:04.419\">Masjid dibakar, kampung dibakar, anak-anak dibunuh, orang tua dibunuh.</p>\\n      <p begin=\"00:00:04.980\" end=\"00:00:05.900\">Mereka pilih tempat kita.</p>\\n      <p begin=\"00:00:06.759\" end=\"00:00:07.759\">Jadi, mereka ini,</p>\\n    </div>\\n  </body>\\n</tt>\\n',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG Persidangan Dewan Rakyat  Mesyuarat Kedua Penggal Ketiga  1 Julai 2024  Sesi Petang [JZLbr5Nbxrs]_001/parlimen-24k-LANGSUNG Persidangan Dewan Rakyat  Mesyuarat Kedua Penggal Ketiga  1 Julai 2024  Sesi Petang [JZLbr5Nbxrs]_001_115.mp3'},\n",
       " {'question': 'transcribe the audio into Whisper format in word timestamp',\n",
       "  'answer': '<|startoftranscript|><|ms|><|transcribeprecise|><|0.00|> Masjid<|0.38|><|0.44|> dibakar,<|0.88|><|1.04|> kampung<|1.44|><|1.50|> dibakar,<|1.98|><|2.26|> anak-anak<|2.74|><|2.82|> dibunuh,<|3.26|><|3.40|> orang<|3.64|><|3.72|> tua<|3.90|><|4.06|> dibunuh.<|4.42|><|4.98|> Mereka<|5.16|><|5.24|> pilih<|5.44|><|5.48|> tempat<|5.68|><|5.72|> kita.<|5.90|><|6.76|> Jadi,<|6.90|><|7.02|> mereka<|7.28|><|7.40|> ini,<|7.76|><|endoftext|>',\n",
       "  'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG Persidangan Dewan Rakyat  Mesyuarat Kedua Penggal Ketiga  1 Julai 2024  Sesi Petang [JZLbr5Nbxrs]_001/parlimen-24k-LANGSUNG Persidangan Dewan Rakyat  Mesyuarat Kedua Penggal Ketiga  1 Julai 2024  Sesi Petang [JZLbr5Nbxrs]_001_115.mp3'}]"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alignment[-10:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "de425549",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'question': 'transcribe the audio into Whisper format in word timestamp',\n",
       " 'answer': '<|startoftranscript|><|ms|><|transcribeprecise|><|0.00|> Masjid<|0.38|><|0.44|> dibakar,<|0.88|><|1.04|> kampung<|1.44|><|1.50|> dibakar,<|1.98|><|2.26|> anak-anak<|2.74|><|2.82|> dibunuh,<|3.26|><|3.40|> orang<|3.64|><|3.72|> tua<|3.90|><|4.06|> dibunuh.<|4.42|><|4.98|> Mereka<|5.16|><|5.24|> pilih<|5.44|><|5.48|> tempat<|5.68|><|5.72|> kita.<|5.90|><|6.76|> Jadi,<|6.90|><|7.02|> mereka<|7.28|><|7.40|> ini,<|7.76|><|endoftext|>',\n",
       " 'audio_filename': 'parlimen-24k-chunk_processed/parlimen-24k-LANGSUNG Persidangan Dewan Rakyat  Mesyuarat Kedua Penggal Ketiga  1 Julai 2024  Sesi Petang [JZLbr5Nbxrs]_001/parlimen-24k-LANGSUNG Persidangan Dewan Rakyat  Mesyuarat Kedua Penggal Ketiga  1 Julai 2024  Sesi Petang [JZLbr5Nbxrs]_001_115.mp3'}"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alignment[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "ba728c17",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "pd.DataFrame(alignment).to_parquet('more-stt.parquet')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "611c541d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Uploading files using Xet Storage..\n",
      "Uploading...: 100%|██████████████████████████| 144M/144M [00:14<00:00, 9.99MB/s]\n",
      "https://huggingface.co/datasets/mesolitica/Transcription-Instructions/blob/main//data/extra_malaysian-00000-of-00001.parquet\n"
     ]
    }
   ],
   "source": [
    "!huggingface-cli upload mesolitica/Transcription-Instructions \\\n",
    "more-stt.parquet /data/extra_malaysian-00000-of-00001.parquet --repo-type=dataset"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
